package datastructure_algorithm.queue;

import java.util.Random;

public class _Test {

	public static void main(String[] args) {

//		testArrayQueue();
//
//		testLoopQueue();
//
		compareQueue();

//		testLinkedListQueue();

	}

	private static void testArrayQueue() {
		Queue<Integer> q = new ArrayQueue<>();
		for (int i = 0; i < 10; i++) {
			q.enqueue(i);
			System.out.println(q);
			if (i % 3 == 2) {
				q.dequeue();
				System.out.println(q);
			}
		}
	}

	public static void testLoopQueue() {
		LoopQueue<Integer> queue = new LoopQueue<>();
		for (int i = 0; i < 10; i++) {
			queue.enqueue(i);
		}
		System.out.println(queue);
		queue.dequeue();
		System.out.println(queue);
	}

	private static void compareQueue() {
		int opCount = 100_000;
		ArrayQueue<Integer> q1 = new ArrayQueue<>();
		double t1 = testQueue(q1, opCount);
		System.out.println("ArrayQueue:" + t1 + "s");
		LoopQueue<Integer> q2 = new LoopQueue<>();
		double t2 = testQueue(q2, opCount);
		System.out.println("LoopQueue:" + t2 + "s");
		LinkedListQueue<Integer> q3 = new LinkedListQueue<>();
		double t3 = testQueue(q3, opCount);
		System.out.println("LinkedListQueue:" + t3 + "s");
	}

	private static double testQueue(Queue<Integer> queue, int opCount) {
		long start = System.nanoTime();
		Random r = new Random();
		for (int i = 0; i < opCount; i++) {
			queue.enqueue(r.nextInt(Integer.MAX_VALUE));
		}
		for (int i = 0; i < opCount; i++) {
			queue.dequeue();
		}
		long end = System.nanoTime();
		return (end - start) / 1_000_000_000.0;
	}

	public static void testLinkedListQueue() {
		LinkedListQueue<Integer> queue = new LinkedListQueue<>();
		for (int i = 0; i < 10; i++) {
			queue.enqueue(i);
		}
		System.out.println(queue);
		System.out.println(queue.dequeue());
		System.out.println(queue.dequeue());
		System.out.println(queue.dequeue());
		System.out.println(queue);
	}
}
